package com.android.panballgame;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import android.widget.ToggleButton;

public class PBSetting extends Activity {
	final PBEngine engine = new PBEngine();	
	private ToggleButton tbtn1, tbtn2;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.setting);

		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
																			
		tbtn1 = (ToggleButton) findViewById(R.id.toggleButton1);
		tbtn2 = (ToggleButton) findViewById(R.id.toggleButton2);

		if (PBEngine.isMusic  == 0)
			tbtn1.setChecked(false);
		if (PBEngine.isSound == 0)
			tbtn2.setChecked(false);
		
		final StringBuffer message1 = new StringBuffer();
		final StringBuffer message2 = new StringBuffer();

		tbtn1.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				if (tbtn1.isChecked()) { // 토클버튼이 ON인 상태인 경우
					PBEngine.isMusic = 1;
					PBMusic.player.start();
					PBMusic.isRunning = true;
					message1.append("배경음악 : ").append(tbtn1.getText());
					Toast.makeText(PBSetting.this, message1.toString(), Toast.LENGTH_SHORT).show();
				}
				else { // 토글버튼이 OFF인 경우
					PBEngine.isMusic = 0;
					PBMusic.player.pause();
					PBMusic.isRunning = false;
					message1.append("배경음악 : ").append(tbtn1.getText());
					Toast.makeText(PBSetting.this, message1.toString(), Toast.LENGTH_SHORT).show();
					}
				message1.setLength(0);
				if(PBEngine.isDb ==1)
					PBMainMenu.db_updatemain();
			}
		});
		tbtn2.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				// Perform action on clicks 버튼음도 사라지게
				if (tbtn2.isChecked()) { // 토클버튼이 ON인 상태인 경우
					PBEngine.isSound = 1;
					message2.append("효과음 : ").append(tbtn2.getText());
					Toast.makeText(PBSetting.this, message2.toString(), Toast.LENGTH_SHORT).show();
				}
				else { // 토글버튼이 OFF인 경우
					PBEngine.isSound = 0;
					message2.append("효과음 : ").append(tbtn2.getText());
					Toast.makeText(PBSetting.this, message2.toString(), Toast.LENGTH_SHORT).show();
				    }
				message2.setLength(0);
				if(PBEngine.isDb ==1)
					PBMainMenu.db_updatemain();
			}
		});
	}	
}
